@extends('admin.common.main')
@section('cnt')
<head>
    <link href="/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
    <meta charset="utf-8">
    <title>房源列表</title>
</head>
<body>
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-sm-4">
            <ol class="breadcrumb">
                <li>
                    <a href="index.html">主页</a>
                </li>
                <li>
                    <strong>房源列表</strong>
                </li>
            </ol>
        </div>
    </div>
    <div class="page-container">
        <div class="form-group">
            <form class="form-inline" method="get" action="{{route('admin.fangattr.index')}}">
                <input type="text" class="form-control" value="{{$params['startTime']}}" id="starttime" name="starttime" autocomplete="off"
                       placeholder="开始日期">~
                <input type="text" class="form-control" value="{{$params['endTime']}}" id="endtime" name="endtime" autocomplete="off"
                       placeholder="结束日期">
                <input type="text" placeholder="请输入关键词"  name="name" id="name" class="form-control" value="{{$params['name']}}">
                <button type="submit" class="btn btn-primary"> 搜索</button>
            </form>
        </div>
        <div class="mt-20">
            <div style="margin-bottom: 10px">
                <a class="btn btn-primary" href="{{route('admin.fangattr.create')}}">
                    <i class="Hui-iconfont">&#xe600;</i> 添加房源
                </a>
            </div>
            <table class="table table-hover table-striped" id="myTable">
                <thead>
                <tr class="text-c">
                    <th width="80">ID</th>
                    <th>房源属性名称</th>
                    <th>图标</th>
                    <th>字段名称</th>
                    <th>加入时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $k=>$v)
                    <tr class="text-c">
                        <td width="80">{{$v['id']}}</td>
                        <td>{{$v['name']}}</td>
                        <td><img height="40px" src="{{env('APP_URL').$v['icon']}}"/></td>
                        <td>{{$v['field_name']}}</td>
                        <td>{{$v['created_at']}}</td>
                        <td class="td-manage">
                            <a href="{{ route('admin.fangattr.edit',['id' => $v['id']]) }}"
                            >修改</a>
                            |
                            <a  href="{{ route('admin.fangattr.destroy',['id' => $v['id']]) }}"
                                class="delBut">删除</a>
                        </td>
                    </tr>
                    @foreach($v['son'] as $k1=>$v1)
                        <tr class="text-c">
                            <td width="80">{{$v1['id']}}</td>
                            <td>-----{{$v1['name']}}</td>
                            <td><img height="40px" src="{{env('APP_URL').$v1['icon']}}"/></td>
                            <td>{{$v1['field_name']}}</td>
                            <td>{{$v1['created_at']}}</td>
                            <td class="td-manage">
                                <a href="{{ route('admin.fangattr.edit',['id' => $v1['id']]) }}"
                                >修改</a>
                                |
                                <a  href="{{ route('admin.fangattr.destroy',['id' => $v1['id']]) }}"
                                 class="delBut">删除</a>
                            </td>
                        </tr>
                    @endforeach
                @endforeach
                </tbody>
            </table>
        </div>
    </div>

    @section('js')
        <script type="text/javascript" src="{{env('APP_URL')}}admin/lib/layer/2.4/layer.js"></script>
        <script type="text/javascript" src="{{env('APP_URL')}}admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
        <script type="text/javascript"
                src="{{env('APP_URL')}}admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
        <script type="text/javascript" src="{{env('APP_URL')}}admin/lib/laypage/1.2/laypage.js"></script>
        <script src="/js/moment-with-locales.min.js"></script>
        <script src="/js/bootstrap-datetimepicker.min.js"></script>
        <script>
            $('#starttime').datetimepicker({locale: 'zh-cn', format: 'YYYY-MM-DD HH:mm:ss',});
            $('#endtime').datetimepicker({locale: 'zh-cn', format: 'YYYY-MM-DD HH:mm:ss'});
            $(document).ready(function() {
                $('#myTable').DataTable({
                    "paging": false,
                    "ordering": false,
                    "searching": false,
                });
            });
            const _token = "{{ csrf_token() }}";
            $(".delBut").click(function () {
                var url = $(this).attr('href');
                $.ajax({
                    url,
                    type: "DELETE",
                    data: {_token},
                    dataType: "json",
                    success: function (res) {
                        if (res.code == 200) {
                            layer.msg(res.msg, {icon: 1, time: 1000});
                        } else {
                            layer.msg(res.msg, {icon: 2, time: 1000});
                        }
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000);
                    }
                });
                return false;
            });
        </script>
    @endsection
</body>
</html>